﻿using System;
using System.Data;
using Service;
using Resources;


public partial class OwnDetail : System.Web.UI.Page
{
    readonly ReferenceDataService _ReferenceDataService = new ReferenceDataService();
    readonly StockService _StockService = new StockService();
    private DirectService _DirectService = new DirectService();
    private int codeNumber = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!new Utility().TestPermissions(Resource.PermissionViewDetailOwner))
        {
            lblPermission.Text = Resource.Permission;
            return;
        }

        codeNumber = GetCodeNumber();
        pnlBody.Visible = codeNumber == 0 ? false : true;
        if (codeNumber == 0) return;


        if(codeNumber>0)
        {

            txtHiddenTypeId.Text = codeNumber.ToString();
           
           _DirectService.GetOwnerEquipment(codeNumber.ToString());
            
            DataTable table = new DataTable();
            table = _DirectService.GetOwnerByCodeNumber(codeNumber.ToString());
            lblEmployee.Text = table.Rows[0]["EmployeeName"].ToString();
            lblBuilding.Text = table.Rows[0]["Building"].ToString();
            lblLocation.Text = table.Rows[0]["location"].ToString();
            lblDepartment.Text = table.Rows[0]["departmentname"].ToString(); 
            lblDateEnter .Text =table.Rows[0]["dateEnter"].ToString();
            lblCodeEquipment.Text = table.Rows[0]["codeNumber"].ToString();
            lblTypeequipment.Text =table.Rows[0]["typeequipment"].ToString();
            lblModel.Text = table.Rows[0]["model"].ToString();
            lblSystem.Text = table.Rows[0]["system"].ToString();
            DataTable table1 = new DataTable();
            string dateFin = "";
            table1=_DirectService.GetHistoryEquipment(codeNumber.ToString());
            for (int i = 0; i < table1.Rows.Count; i++)
            {
                if (i == 0) grdHistory.Rows[0].Cells[2].Text = "UnKnow";
                else
                {
                    grdHistory.Rows[i].Cells[2].Text = dateFin; 
                }
                dateFin = grdHistory.Rows[i].Cells[1].Text;
            }

            
        }
    }
    public int GetCodeNumber()
    {
        return !String.IsNullOrEmpty(Request.QueryString["codenumber"]) ? Int32.Parse(Request.QueryString["codenumber"]) : 0;
    }
    protected void grdCompose_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        new Utility().SetSelectedColorToGridView(e, grdCompose);
    }
    protected void grdHistory_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        new Utility().SetSelectedColorToGridView(e, grdHistory);
    }
}
